package org.cuatrovientos.ImperialFleet;
import java.util.Scanner;
/**
 * 	This class represents a generic SpaceShip with the call to the constructs of different types
 * 
 * HE CAMBIADO LAS CLASES DE LAS NAVES, EN MI OPINION ESTO ES MUCHO MAS LOGICO ASI
 * LOS ATRIBUTOS DE LAS NAVES ESTAN EN LA SUPERCLASE Y TODOS SON HEREDADOS
 * SALVO EL NOMBRE DEL PILOTO QUE SE OBTIENE MEDIANTE OTRO METODO, ADEMAS
 * LAS NAVES SE CONSTRUYEN DESDE LA SUPERCLASE, LO QUE ME PARECE MAS LOGICO Y FACIL
 * DE ENTENDER.
 * 
 * LOS METODOS PARA DISPARAR NO SE COMO HACERLOS MAS SENCILLOS, HE METIDO CONSTANTES
 * TANTO EN ESOS METODOS COMO EN LOS ATRIBUTOS DE LOS TIE PARA HACERLO TODO MAS CLARO.
 * 
 * TAMBIEN HE METIDO LOS GETTERS Y SETTERS Y EL TOSTRING DE LA SUPERCLASE
 * 
 * @author Sienar Fleet Systems
 * @greets The Emperor
 */
public class SpaceShip {
	protected int type;
	protected int bombs;
	protected int speed;
	protected int range;
	protected int energy;
	private String pilotName;
	
	/**
	 * Constructor of the SpaceShip, includes calls to the constructors of the specific ships
	 * @param type
	 */
	public SpaceShip (int type)  {
		this.type = type;
		switch (type) {
		case 1 : new TieFighter();
			this.pilotName = NamePilot();
			break;
		case 2 : new TieAdvanced();
			this.pilotName = NamePilot();
			break;
		case 3 : new TieBomber();
			this.pilotName = NamePilot();
			break;
		}
	}
	
	/**
	 * Method to establish the name of a pilot
	 * @return
	 */
	public String NamePilot (){
		String name = "";
		Scanner reader = new Scanner(System.in);
		System.out.println("Who is the pilot of this ship?");
		name = reader.nextLine();
		reader.close();
		return name;
	}
	
	/**
	 * This method returns the damage of the bomb, only available on bombers
	 * @return
	 */
	public int dropBomb () {
		final int BOMB_DAMAGE = 5;
		if (bombs == 1){return BOMB_DAMAGE;}
		return 0;
	}
	
	/**
	 * This method returns the damage of the Ion Cannon, only available on TieFighters and TieAdvanceds
	 * @return
	 */
	public int fireIonCannon () {
		final int ION_CANNON = 3;
		if (type==1 || type==2) {return ION_CANNON;}
		return 0;
	}
	
	/**
	 * This metod returns the damage of the Laser, available on all ships
	 * @return
	 */
	public int fireLaser () {
		final int LASER = 0;
		switch (type) {
			case 1: return LASER +1;
			case 2: return LASER +2;
			case 3: return LASER +1;
			default: return 0;
		}	
	}
	
	/**
	 * This method moves the ship, depending on its type
	 * @return
	 */
	public int move () {
		switch (type) {
			case 1: return speed;
			case 2: return speed;
			case 3: return speed;
			default:return 0;
		}
	}

	/**
	 * Getters & Setters
	 * @return
	 */
	public int getBombs() {
		return bombs;
	}

	public void setBombs(int bombs) {
		this.bombs = bombs;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public int getSpeed() {
		return speed;
	}

	public void setSpeed(int speed) {
		this.speed = speed;
	}

	public String getPilotName() {
		return pilotName;
	}

	public void setPilotName(String pilotName) {
		this.pilotName = pilotName;
	}
	
	/**
	 * ToString method
	 */
	public String toString() {
		return "SpaceShip [type=" + type + ", bombs=" + bombs + ", speed="
				+ speed + ", range=" + range + ", energy=" + energy
				+ ", pilotName=" + pilotName + "]";
	}
	
	
		
}
